<template>
  <div>
    <component
      v-bind:is="currentTabComponent"
      title="用款申请"
      :showBackBtn="true"
    >
      <a-icon
        slot="action"
        type="plus"
        @click="$commonJs.goPage('addMoney')"
      ></a-icon>
      <div slot="content" class="wrapper">
        <div class="project">
          <money-tab
            :tabInfo="tabInfo"
            @changeStatus="changeStatus"
            :info="info"
            @changeSearch="changeSearch"
          ></money-tab>
          <a-button
            v-if="isPC"
            type="primary"
            class="add"
            @click="$commonJs.goPage('addMoney')"
            ><a-icon type="plus"></a-icon>发起用款申请</a-button
          >
        </div>
        <a-table
          :columns="isPC ? columns : mobileColumns"
          :dataSource="data"
          @change="changePagination"
          :pagination="paginationInfo"
          rowKey="id"
          :scroll="{ x: 496 }"
        >
          <span slot="status" slot-scope="text">
            <span v-if="text === 1"
              ><i class="iconfont icondaishenhe"></i>待审核</span
            >
            <span v-else-if="text === 2" class="text-green"
              ><i class="iconfont iconyitongguo"></i>已通过</span
            >
            <span v-else class="text-red"
              ><i class="iconfont iconyijujue"></i>已拒绝</span
            >
          </span>
        </a-table>
      </div>
    </component>
  </div>
</template>

<script>
export default {
  name: "index",
  components: {
    moneyTab: () => import("@/components/commonTab/index"),
    pcWrapper: () => import("@/components/contentWrapper/pcWrapper"),
    contentWrapper: () => import("@/components/contentWrapper/index")
  },
  data() {
    return {
      data: [],
      tabInfo: [
        { key: "0", tab: "所有项目" },
        { key: "1", tab: "待审核", filed: "waitCheck" },
        { key: "3", tab: "已拒绝", filed: "error" },
        { key: "2", tab: "已通过", filed: "success" }
      ],
      columns: [
        {
          title: "项目名称",
          align: "center",
          dataIndex: "project_name"
        },
        { title: "申请金额（元）", dataIndex: "money" },
        {
          title: "状态",
          dataIndex: "status",
          align: "center",
          scopedSlots: { customRender: "status" }
        },
        { title: "备注", align: "center", dataIndex: "systerm_msg" },
        {
          title: "创建时间",
          dataIndex: "create_time",
          align: "center"
        }
      ],
      mobileColumns: [
        {
          title: "项目名称",
          dataIndex: "project_name",
          fixed: "left",
          width: 120
        },
        { title: "申请金额", width: 98, dataIndex: "money" },
        {
          title: "状态",
          dataIndex: "status",
          width: 98,
          scopedSlots: { customRender: "status" }
        },
        { title: "创建时间", dataIndex: "create_time", width: 180 }
      ],
      status: null,
      paginationInfo: {
        total: 0,
        current: 1,
        pageSize: 10
      },
      project_name: "",
      info: {
        waitCheck: 0,
        success: 0,
        error: 0
      }
    };
  },
  methods: {
    changeStatus(key) {
      if (key === "0") {
        this.status = null;
      } else {
        this.status = key;
      }
      this.getList();
    },
    changeSearch(values) {
      this.project_name = values.project_name;
      this.getList();
    },
    changePagination(pagination) {
      Object.assign(this.paginationInfo, pagination);
      this.getList();
    },
    getList() {
      let obj = {
        pageNumber: this.paginationInfo.current,
        pageSize: this.paginationInfo.pageSize,
        project_name: this.project_name,
        type: this.status
      };
      this.$ajax
        .post(this.$api.moneyList, obj)
        .then(res => {
          this.info.waitCheck = res.waitCheck;
          this.info.success = res.success;
          this.info.error = res.error;
          this.paginationInfo.total = res.total;
          this.data = res.data;
        })
        .catch(err => {
          this.$message.error(err);
        });
    }
  },
  created() {
    this.getList();
  },
  computed: {
    currentTabComponent() {
      if (this.$store.state.isPC) {
        return "pcWrapper";
      } else {
        return "contentWrapper";
      }
    },
    isPC() {
      return this.$store.state.isPC;
    }
  }
};
</script>

<style scoped lang="less">
.project {
  position: relative;
  margin-bottom: 1.25rem;
  .add {
    position: absolute;
    right: 0;
    top: 0;
  }
}
.iconfont {
  display: inline-block;
  margin-right: 5px;
}
</style>
